const jsonwebtoken = require("jsonwebtoken")
let accessToken = []
require("dotenv").config()
const add_accessToken = (token)=>{
  let index = accessToken.findIndex(i=>i[1]===token[1])
  accessToken.splice(index,1)
  accessToken.push(token)
}
const delete_access = (id)=>{
  let index = accessToken.findIndex(i=>i[1]===id)
  accessToken.splice(index,1)
}
const yz_accessToken = (token)=>{
    let index = accessToken.findIndex(i=>i[0]===token)
    if(index==-1){return 209}
    return jsonwebtoken.verify(token, process.env.ACCESS_TOKEN_SECRET, (err) => {
        if (err) {
          accessToken.splice(index,1)
          return 209
        } else {
          return 200
        }
      });
}
module.exports = {add_accessToken,yz_accessToken,delete_access}
